package main

import "fmt"

func main() {
	s := []int8{1, 2, 3, 4, 5}
	fmt.Printf("Original slice is: %v\n", s)
	reverse(s)
	fmt.Printf("Reversed slice is: %v\n", s)

	reverse(s[:2])
	reverse(s[2:])
	reverse(s)
	fmt.Printf("Rotate s left by two positions: %v\n", s)

	reverse(s[len(s)-2:])
	reverse(s[:len(s)-2])
	reverse(s)
	fmt.Printf("Rotate s right by two positions: %v\n", s)
}

func reverse(s []int8) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}
